package cn.edu.ujs.coor.repository.user;

import cn.edu.ujs.coor.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户Repository
 *
 * @author 柳曾雄
 * @date 2018-07-16
 */
@Repository
public interface UserRepository extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {

    /**
     * 根据编号/联系方式/邮箱查询用户信息
     * @param key
     * @return
     */
    @Query("from User u where u.id = ?1 or u.phone = ?1 or u.email = ?1")
    User findByIdOrPhoneOrEmail(String key);

    User findByPhone(String phone);

    User findByEmail(String email);

    List<User> findByOrganizationId (String organizationId);

    List<User> findByOrganizationIdAndNameLike (String organizationId, String name);
}
